package com.ordos.recruit.module.user.helper;

import com.ordos.recruit.module.user.constant.Conf;
import com.ordos.recruit.module.user.entity.SysSsoUserDto;

public class SsoLoginStoreHelper {

    /**
     * 1440 minute, 24 hour
     */
    private static final int REDIS_EXPIRE_MINUTE = 1440;

    public static int getRedisExpireMinute() {
        return REDIS_EXPIRE_MINUTE;
    }


    /**
     * get
     *
     * @param storeKey userId
     * @return SsoUser
     */
    public static SysSsoUserDto get(String storeKey) {

        String redisKey = redisKey(storeKey);
        Object objectValue = JedisUtilHelper.getObjectValue(redisKey);
        if (objectValue != null) {
            return (SysSsoUserDto) objectValue;
        }
        return null;
    }

    /**
     * remove
     *
     * @param storeKey userId
     */
    public static void remove(String storeKey) {
        String redisKey = redisKey(storeKey);
        JedisUtilHelper.del(redisKey);
    }

    /**
     * put
     *
     * @param storeKey userId
     * @param ssoUser ssoUser
     */
    public static void put(String storeKey, SysSsoUserDto ssoUser) {
        String redisKey = redisKey(storeKey);
        // minute to second
        JedisUtilHelper.setObjectValue(redisKey, ssoUser, REDIS_EXPIRE_MINUTE * 60);
    }

    /**
     * put
     *
     * @param storeKey userId
     * @param val val
     */
    public static void put(String storeKey, String val) {
        String redisKey = redisKey(storeKey);
        // minute to second
        JedisUtilHelper.setObjectValue(redisKey, val, REDIS_EXPIRE_MINUTE * 60);
    }

    private static String redisKey(String sessionId){
        return Conf.SSO_SESSIONID.concat(":").concat(sessionId);
    }

}
